<?php
/**
 * Workflow JSON API
 * This interface will return current mission workflow steps
 * 
 */

use Hive\Mission;
$xview = Xview::instance();
$missionid = $xview->val('mission');
$mode = $xview->val('mode');
$deepness = $xview->val('deepness');
$rid = $xview->val('rid');

try {
	$mission = Fox\Dao::load(Mission::className(),$missionid);
	$workflow = $mission->workflow();
	
	switch ($deepness) {
		case 'steps' :
			if($mode == 'droplist') {
				$default = null;
				if(!empty($rid)) {
					$partnerLink = $mission->partnerLink($rid);
					$default = $partnerLink->status;
				}
				foreach($workflow->steps() as $step) {
					
					$item = array('value' => $step->stepid,'label' => $step->label());
					if($default == $step->stepid) {
						$item['selected'] = true;
					}
					$data[] = $item;
				}
			} else { 
				
			}
			echo Fox\Utilities::jsonUTF8Encode($data);
		break;
	}
} catch(Fox\Object\Exception\NotExist $e) {
	
}